package com.ych.sys.controller;

import com.ych.redis.util.RedisShareLockUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsProject: ape-frame
 * @BelongsPackage: com.ych.sys.controller
 * @Author: ych
 * @CreateTime: 2024-11-26  10:15
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("test")
@Slf4j
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private RedisShareLockUtil redisShareLockUtil;

    @GetMapping("/testRedis")
    public String testRedis() {
        redisTemplate.opsForValue().set("name", "ych");
        return (String) redisTemplate.opsForValue().get("name");
    }

    ;

    @GetMapping("/testRedisShareLock")
    public String testRedisShareLock() {
        boolean result = redisShareLockUtil.lock("ych", "123456", -1L);
        log.info("分布式锁获取：{}", result);
        return String.valueOf(result);
    }
}
